<!--
 * Copyright © 2023
 * @Author: zhangxiang
 * @Date: 2023-07-25 14:47:26
 * @LastEditors: zhangxiang
 * @LastEditTime: 2023-07-26 10:53:07
 * @Description:
 *
-->

<template>
  <div class="block-storage-config">
    <BlockFormAliyun
      v-if="parentCloudProvider === '阿里云'"
      ref="createForm"
      :scene="'orchestrate'"
      :info="form"
    />
    <BlockFormHuawei
      v-if="parentCloudProvider === '华为云'"
      ref="createForm"
      :scene="'orchestrate'"
      :info="form"
    />
    <BlockFormOpenstack
      v-if="parentCloudProvider === 'Openstack'"
      ref="createForm"
      :scene="'orchestrate'"
      :info="form"
    />
  </div>
</template>

<script>
import commonMixin from './commonMixin.js'
import BlockFormAliyun from './child/BlockFormAliyun.vue'
import BlockFormHuawei from './child/BlockFormHuawei.vue'
import BlockFormOpenstack from './child/BlockFormOpenstack.vue'

export default {
  components: {
    BlockFormAliyun,
    BlockFormHuawei,
    BlockFormOpenstack
  },
  mixins: [commonMixin],
  props: ['params', 'GraphApi', 'cell'],
  data() {
    return {
      form: {
        cpRegionId: '', // 区域
        zone: '', // 可用区
        encrypted: false, // 是否加密
        type: '', // 云盘类型
        size: 20, // 云盘大小
        desc: ''
      }
    }
  },
  mounted() {
    this.form = Object.assign(
      {},
      this.form,
      this.params.attribute || {},
      this.parentAttribute
    )
  },
  methods: {
    /**
     * @description: 保存配置
     * @param {*} callback
     * @return {*}
     */
    saveConfig(callback) {
      this.$refs.createForm.validateForm((form) => {
        const businessData = JSON.parse(JSON.stringify(this.params))
        businessData.attribute = form
        this.GraphApi.setObjectData(
          this.params.id,
          JSON.stringify(businessData)
        )
        this.cell.setValue(businessData.attribute.name || '云盘')
        this.GraphApi.refresh(this.cell)
        callback()
      })
    }
  }
}
</script>
